package com.java.zhuiyun.api.carousel.controller;

import com.java.zhuiyun.api.carousel.entity.Carousel;
import com.java.zhuiyun.api.carousel.service.CarouselService;
import com.java.zhuiyun.common.response.CommonResult;
import com.java.zhuiyun.util.pageUtil.PageRequest;
import com.java.zhuiyun.util.pageUtil.PageResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @ClassName CarouselController
 * @Description TODO
 * @Author wuwan
 * @Date 2023/8/15 16:19
 **/
@Slf4j
@RestController
@CrossOrigin
@RequestMapping("/Carousel")
public class CarouselController {
    @Autowired
    private CarouselService carouselService;
    /*
    * @Author wuwan
    * @Description todo 轮播图数据查询
    * @Date 2023/8/15 16:28
    * @Return
    * @param null
    */
    @GetMapping("/getCarousel")
    public CommonResult getCarousel(PageRequest pageRequest){
        PageResult carousel = carouselService.getCarousel(pageRequest);
        return CommonResult.ok(carousel);
    }
    /*
    * @Author wuwan
    * @Description todo 轮播图信息添加
    * @Date 2023/8/15 21:03
    * @Return
    * @param null
    */
    @PostMapping("/addCarousel")
    public CommonResult addCarousel(Carousel carousel, MultipartFile file){
        return CommonResult.ok(carouselService.addCarousel(carousel,file));
    }
    /*
    * @Author wuwan
    * @Description todo 轮播图信息修改
    * @Date 2023/8/16 16:11
    * @Return
    * @param null
    */
    @PostMapping("/updateCarousel")
    public CommonResult updateCarousel(Carousel carousel, MultipartFile file){
        return CommonResult.ok(carouselService.updateCarousel(carousel, file));
    }
    /*
     * @Author wuwan
     * @Description todo 轮播图启用方法
     * @Date 2023/8/16 16:05
     * @Return
     * @param null
     */
    @PostMapping("/ReleaseCarousel")
    public CommonResult ReleaseCarousel(Integer id,Integer carouselStatus) {
        return CommonResult.ok(carouselService.ReleaseCarousel(id,carouselStatus));
    }
    /*
     * @Author wuwan
     * @Description todo 轮播图删除方法
     * @Date 2023/8/16 16:05
     * @Return
     * @param null
     */
    @PostMapping("/deleteData")
    public CommonResult deleteData(Integer id) {
        return CommonResult.ok(carouselService.deleteData(id));
    }
}
